package Ratio

import (
	"crypto/rand"
	"fmt"
	"math/big"
)

const (
	RandomMin = int64(3000)
	RandomMax = int64(10000)
)

type TestModel struct {
	Start int64
	End   int64
	Level int64
}

var (
	Ratio        = []int64{1, 10, 10, 19, 20, 10, 30}
	offset       = (RandomMax - RandomMin) / 100
	lastVipRange int64
	l            = []TestModel{}
	TimesMap     = map[int64]int{}
)

func init() {
	l = make([]TestModel, len(Ratio))
	TimesMap = make(map[int64]int, 0)
	for i, r := range Ratio {
		l[i].Start = lastVipRange
		l[i].End = lastVipRange + r*offset
		lastVipRange = l[i].End
		l[i].Level = (int64)(i)
	}
}

func TestRandValues() bool {
	c := 0
	n, _ := rand.Int(rand.Reader, big.NewInt(RandomMax-RandomMin))
	rNumber := n.Int64()
	for i := 6; i >= 0; i-- {
		if rNumber >= l[i].Start && rNumber <= l[i].End {
			TimesMap[l[i].Level] += 1
			//fmt.Println("rand :", rNumber, l[i], i)
			return true
		}
		c++
		if c == 7 {
			fmt.Println("rand :", rNumber, l[i], i)
		}
	}
	return false
}
